/*
 *--------------------------------------------------------------------------
 *   Battlefield - A Realtime Network Multiplayer Game
 *   =======================================================
 *   Developed by Group D02 - 2009/2010 Semester 4 - CS2103
 *     Harry Nguyen Duy Hoang <nnduyhoang@yahoo.co.uk>
 *     Kent Chng Siang Rong <fivefootway@gmail.com>
 *     Lim Yong Peng <limpeng1986@gmail.com>
 *     Loh Xiankun <u0807185@nus.edu.sg>
 *   Instructed by
 *     Dr. Damith C.Rajapakse <damith@gmail.com>
 *   =======================================================
 *   $Id: NormalWhiteButton.java 601 2010-07-26 18:46:36Z Harry $
 *   $LastChangedDate: 2010-07-26 18:46:36 +0000 (Mon, 26 Jul 2010) $
 *   $LastChangedBy: Harry $
 *--------------------------------------------------------------------------
 */
package battlefield.ui.component;

import battlefield.resource.Graphics;
import battlefield.resource.Sounds;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics2D;
import java.awt.Image;
import java.awt.Insets;
import java.awt.event.ActionListener;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import javax.swing.JButton;
import javax.swing.SwingConstants;
import javax.swing.plaf.basic.BasicButtonUI;

/**
 *
 * @author Yong Peng
 */
public class NormalWhiteButton extends JButton implements MouseListener {

    private static int fontSize = 14;
    private static int whiteBtnComponentWidth = 110;
    private static int whiteBtnComponentHeight = 35;
    private Image backgroundImage;

    public NormalWhiteButton(String text, ActionListener al) {
        super(text);
        this.setFocusPainted(false);
        this.setBorderPainted(false);
        this.setContentAreaFilled(false);
        this.setMargin(new Insets(0, 0, 0, 0));
        this.setOpaque(false);
        this.addActionListener(al);
        this.addMouseListener(this);
        this.setFont(new java.awt.Font("Century Gothic", 0, fontSize));
        this.backgroundImage = Graphics.BUTTON_MENU_WHITE_NORMAL.getImage();
        this.setHorizontalTextPosition(SwingConstants.CENTER);
        this.setVerticalTextPosition(SwingConstants.CENTER);
        this.setForeground(Color.black);
        this.setSize(new Dimension(whiteBtnComponentWidth, whiteBtnComponentHeight));
        this.setPreferredSize(new Dimension(whiteBtnComponentWidth, whiteBtnComponentHeight));
        this.setUI(new BasicButtonUI());
    }

    @Override
    public void paintComponent(java.awt.Graphics g) {
        Graphics2D g2d = (Graphics2D) g.create();
        //g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, this.isSelected() ? 1f : 0.6f));
        g2d.drawImage(backgroundImage, 0, 0, this);
        super.paintComponent(g2d);
        g2d.dispose();
    }

    public void mouseClicked(MouseEvent e) {
    }

    public void mousePressed(MouseEvent e) {
        Sounds.MOUSE_CLICK.play();
    }

    public void mouseReleased(MouseEvent e) {
    }

    public void mouseEntered(MouseEvent e) {
        this.backgroundImage = Graphics.BUTTON_MENU_WHITE_HOVER.getImage();
        this.setForeground(Color.WHITE);
        this.repaint();
        Sounds.MOUSE_HOVER.play();
    }

    public void mouseExited(MouseEvent e) {
        this.backgroundImage = Graphics.BUTTON_MENU_WHITE_NORMAL.getImage();
        this.setForeground(Color.BLACK);
        this.repaint();
    }
}
